/*
 * Copyright (c) 2006, 2021, webrx.cn All rights reserved.
 *
 */
package cn.webrx;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;

/**
 * <p>Project: javase - List7
 * <p>Powered by webrx On 2021-12-09 09:40:24
 *
 * @author webrx [webrx@126.com]
 * @version 1.0
 * @since 17
 */
public class List7 {
    public static void main(String[] args) {
        var list = new ArrayList<User>(List.of(new User(100, "李四", 60), new User(2, "张三丰", 20), new User(3, "李四", 30), new User(4, "周五", 70), new User(5, "王六", 80), new User(9, "李丽", 20), new User(11, "李四", 99)));

        //打乱顺序
        Collections.shuffle(list);
        System.out.println(list);
        //根据成绩升序
        list.sort((a, b) -> b.getScore() - a.getScore());
        list.forEach(System.out::println);

        //根据ID降序
        list.sort(Comparator.comparingInt(User::getId));
        list.forEach(System.out::println);
    }
}
